/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alarmlistener;

import alarmlistener.logger.logGui.LogFrame;
import java.awt.AWTException;
import java.awt.MenuItem;
import java.awt.MenuShortcut;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author rbs
 */
public class TrayButton {
    private PopupMenu menu;
    private MenuItem mi1, mi2, mi3;
    private TrayIcon icon;
    private SystemTray tray;


    public TrayButton() throws AWTException {
        menu = new PopupMenu("FW-Disp-Server");
        mi1 = new MenuItem("Beenden", new MenuShortcut('B'));
        mi1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        mi2 = new MenuItem("Demo", new MenuShortcut('D'));
        mi2.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
                    //Runtime.getRuntime().exec("taskmgr");
                    Runtime.getRuntime().exec("java -jar FWDisp.jar --fmslaunch \"BR BRAND_2 MELDER CHL HOHENSTEIN-E DEMOSTR. 4 DEMO-FIRMA ENR:2311\" 001001A");
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(null, "Fehler beim Starten...");
                }
            }
        });
   

        mi3 = new MenuItem("Log", new MenuShortcut('L'));
        mi3.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                new LogFrame();
            }
        });
        
        menu.add(mi1);
        menu.add(mi2);
        menu.add(mi3);
        icon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/alarmlistener/tray_icon.gif")), "FWDisp-Server", menu);
        icon.setImageAutoSize(true);
        tray = SystemTray.getSystemTray();
        tray.add(icon);
    }

}
